import React from 'react';
import { routerRedux } from 'dva/router';
import styles from './styles.less';
import { connect } from 'dva';

// 问诊单编写及诊断
const Comment = ({ dispatch, comment, location, ...rest }) => {

  const status = parseInt(comment.inqStatus, 10);
  const getInquiryMessage = () => {
    switch (status) {
      case 0:
        return {
          title: `${location.state.doctor}发来了问诊单`,
          notes: `请您填写...`,
        };
      case 1:
        return {
          title: `您完成了问诊单`,
          notes: '等待医生诊断',
        };
      case 2:
        return {
          title: '医生诊断了您的问诊单',
          notes: '请查看...',
        };
      default:
        return {
          title: `${location.state.doctor}发来了问诊单`,
          notes: `请您填写...`,
        };
    }
  };

  const goto = () => {
    if (status === 1) {
      return;
    }

    const router = { state: { id: comment.messages, messages: comment.messages } };

    if (status === 0) {
      router.pathname = '/healthy/archives/inquiry/sheet';
    }

    if (status === 2) {

      router.pathname = `/healthy/archives/inquiry/${comment.messages}`;
      
    }
    dispatch(routerRedux.push(router));
  }

  const inquiryMessage = getInquiryMessage();

  let content;
  switch (comment.msgType) {
    // 图片
    case 1:
      content = (
        <img src={comment.messages} />
      );
      break;
    // 问诊单id
    case 2:
      content = (
        <div className={styles.card} onClick={goto}>
          <img
            className={styles.commentIcon}
            src={require('../../assets/icons/icon-doc-checkup.svg')} />
          {inquiryMessage.title}
          <p className={styles.commentNotes}>
            {inquiryMessage.notes}
          </p>
        </div>
      );
      break;
    // 慢病保养文章 url
    case 3:
      content = (
        <a href={comment.messages} target="_blank">查看慢病保养</a>
      );
      break;
    // Msgtype: 0 文字内容
    default:
      content = comment.messages;
      break;
  }

  let commentType = null;
  switch (comment.sendType) {
    case 0:
      commentType = styles.commentUser;
      break;
    case 1:
      commentType = styles.commentDoctor;
      break;
    default:
      // ...
  }
  
  return (
    <div className={styles.commentContainer}>
      <div className={`${styles.comment} ${commentType}`}>
        {content}
      </div>
    </div>
  );
};

export default connect()(Comment);
